import processing.serial.*; Serial thisPort; // Create object from Serial class int xPos = 0; // starting position for graphing void setup() { size(800,700); //make our canvas 800 x 700 pixels println(Serial.list()); //show available ports thisPort = new Serial(this, Serial.list()[0], 9600); thisPort.bufferUntil('\n'); //set the port to store incoming data background(0); //set background color for the window } void draw() { stroke(127,34,255); //set stroke color line(xPos, height, xPos, height - inByte); //draw a line if (xPos >= width) { //if the screen has filled with the graph xPos = 0; //reset position in X to 0 background(0); //reset background } else { //otherwise xPos++; //advance one pixel to draw next line } } void serialEvent(Serial thisPort) { String inString = thisPort.readStringUntil('\n'); // store data read from serial //in a String type variable if (inString != null) { //if there is information read from serial inString = trim(inString); //removes whitespace characters fro //the beginning and end of a String inByte = float(inString); //convert serial data to a flat type number println(inByte); //show value inByte = map(inByte, 0, 40, 0, height); //re-maps a number from one range to another } }